{extend name="public:base" /}
{block name="css"}
<style type="text/css">
    .hide{display: none}
</style>
{/block}

{block name="content"}




<div style="width: 800px; padding-top: 30px;">
    <form method="post"  class="layui-form" action='{:url("Goods/edit")}' enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$Arr['id'] ? $Arr['id'] : 0}">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input" value="{$Arr['name']? $Arr['name'] : ''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <input type="text" name="keyword"  lay-verify="required" autocomplete="off" class="layui-input" value="{$Arr['keyword']? $Arr['keyword'] : ''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品类型</label>
            <div class="layui-input-block">
              <input type="radio" lay-filter="erweima" name="type" value="1" title="产品" {$Arr['type'] == 1 ? 'checked' : ''}>
              <input type="radio" lay-filter="erweima" name="type" value="2" title="会员"{$Arr['type'] == 2 ? 'checked' : ''}>
              <input type="radio" lay-filter="erweima" name="type" value="3" title="代理"{$Arr['type'] == 3 ? 'checked' : ''}>
            </div>
          </div>
      <div class="chengping" style="display: {$Arr['type'] == 1 ? 'block' : 'none'}">
            <div class="layui-form-item">
                <label class="layui-form-label">会员价</label>
                <div class="layui-input-inline">
                    <input type="text" name="price" lay-verify="required"  autocomplete="off" class="layui-input" value="{$Arr['price']? $Arr['price'] : ''}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">首购价</label>
                <div class="layui-input-inline">
                    <input type="text" name="first_price" lay-verify="required"   autocomplete="off" class="layui-input" value="{$Arr['first_price']? $Arr['first_price'] : ''}">
                </div>
            </div>
        </div>

        <div class="huiyuan" style="display:{$Arr['type'] == 2 ? 'block' : 'none'}">
            <div class="layui-form-item">
                <label class="layui-form-label">充值金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="cz_price" autocomplete="off" class="layui-input" value="{$Arr['cz_price']? $Arr['cz_price'] : ''}">
                </div>
            </div>
        </div>

        <div class="daili" style="display: {$Arr['type'] == 3 ? 'block' : 'none'}"}>
            <div class="layui-form-item">
                <label class="layui-form-label">充值金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="dl_price"  autocomplete="off" class="layui-input" value="{$Arr['dl_price']? $Arr['dl_price'] : ''}">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="sort"  lay-verify="sort" autocomplete="off" class="layui-input" value="{$Arr['sort']? $Arr['sort'] : '1'}">
            </div>
            <div class="layui-form-mid layui-word-aux">请输入1-99</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否上线</label>
            <div class="layui-input-inline">
                <select name="status">
                    <option value="1" 
                    {$Arr['status'] == 1 ? 'selected' : ''}
                    >上线</option>
                    <option value="2" 
                    {$Arr['status'] == 2 ? 'selected' : ''}
                    >下线</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品图片</label>
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                    <div class="layui-upload-list">
                        <img src="{$Arr['images']? $Arr['images'] : ''}" class="layui-upload-img" id="demo1" width="100px" height="100px">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
            <input type="hidden" id="fileImg" name="images" value="{$Arr['images']? $Arr['images'] : ''}">
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品详情</label>
            <div class="layui-input-block">
                <textarea name="details" id="editor" type="text/plain"   style="height: 600px; width: 100%">{$Arr['details']? $Arr['details'] : ''}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            </div>
        </div>
    </form>
</div>

{/block}


{block name="javascript"}
<script src="__ADMIN__/js/fromCommon.js" charset="utf-8"></script>
<script charset="utf-8" src="__COMMON__/ueditor/ueditor.config.js"></script>
<script charset="utf-8" src="__COMMON__/ueditor/ueditor.all.min.js"></script>
<script charset="utf-8" src="__COMMON__/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form;
        var layer = layui.layer;

        //自定义验证规则
        form.verify({

            sort: function(value){
                if( value == "" || 0 > parseInt(value) || parseInt(value) > 99 ){
                    return '请输入排序1到99数字';
                }
            }
        });

        form.on('radio(erweima)', function (data) {
            if(data.value == 1){
                $(".chengping").css('display','block');
                $(".huiyuan").css('display','none');
                $(".daili").css('display','none');
                $("input[name=price]").attr('lay-verify',"required");
                $("input[name=first_price]").attr('lay-verify',"required");
                $("input[name=cz_price]").removeAttr('lay-verify');
                $("input[name=dl_price]").removeAttr('lay-verify');
                $("input[name=cz_price]").val('');
                $("input[name=dl_price]").val('');
            }else if(data.value == 2){
                $(".chengping").css('display','none');
                $(".huiyuan").css('display','block');
                $(".daili").css('display','none');
                $("input[name=price]").removeAttr('lay-verify');
                $("input[name=first_price]").removeAttr('lay-verify');
                $("input[name=cz_price]").attr('lay-verify',"required");
                $("input[name=dl_price]").removeAttr('lay-verify');
                $("input[name=price]").val('');
                $("input[name=first_price]").val('');
                $("input[name=dl_price]").val('');
            }else{
                $(".chengping").css('display','none');
                $(".huiyuan").css('display','none');
                $(".daili").css('display','block');
                $("input[name=price]").removeAttr('lay-verify');
                $("input[name=first_price]").removeAttr('lay-verify');
                $("input[name=cz_price]").removeAttr('lay-verify');
                $("input[name=dl_price]").attr('lay-verify',"required");
                $("input[name=price]").val('');
                $("input[name=first_price]").val('');
                $("input[name=cz_price]").val('');
            }

        });

        //各种基于事件的操作，下面会有进一步介绍


//        //监听提交
//        form.on('submit(formDemo)', function(data){
//            var url = $("#from").attr("data-url");
//            $.ajax({
//                type: 'POST',
//                url: url,
//                dataType: 'json',
//                data: data.field,
//                success: function (da) {
//                    if( da.result == 0 ){
//                        prompt_From_one("编辑成功！");
//                    }else{
//                        prompt_From_one("编辑失败！");
//                    }
//                }
//            });
//            return false;
//        });

    });


    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '{:url("goods/up_image")}' //上传接口
            ,done: function(res){
                if(res.code == 0){
                    var da = res.msg;
                    $('#demo1').attr('src', da.imgUrl); //图片链接（base64）
                    $("#fileImg").val(da.imgUrl);
                }else{
                    return layer.msg('上传失败');
                }
            }

        });
    });

    $(document).ready(function() {

        ue = UE.getEditor('editor', {
            autoHeightEnabled: false, toolbars: [
                [
                    'fullscreen',
                    'source',
                    'undo',
                    'redo',
                    'bold',
                    'indent',
                    'snapscreen',
                    'simpleupload', //单图上传
                    'insertimage',
                    'justifyleft', //居左对齐
                    'justifyright', //居右对齐
                    'justifycenter', //居中对齐
                    'justifyjustify', //两端对齐
                    'forecolor', //字体颜色
                    'backcolor', //背景色
                    'link', //超链接
                    'emotion', //表情
                ]

            ]
        });
    });
</script>
{/block}